﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DAL;
using CommontLibrary;
public partial class admin_listTimKiemNguoiTimNguon : System.Web.UI.UserControl
{

#region "Member variables"
    private int intUserID = 0;
    private int intModuleID = 0;
    bool boolRead = false;
    bool boolWrite = false;
    bool boolUpdate = false;
    bool boolDelete = false;
    DANguoiTimNguon objNguoiTimNguon;
    DANguoidung objNguoidung;
#endregion

#region "Private methods"
    // Hien thi NguoiTimNguon tren datagrid
    private void loadNguoiTimNguon()
    {
        DataSet dsNguoiTimNguon = objNguoiTimNguon.loadNguoiTimNguon();
        BindData.bindGridView(this.ddlNguoiTimNguon, dsNguoiTimNguon);
    }
    // Xoa NguoiTimNguon
    private void DeleteNguoiTimNguon(object source, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
    {
        int intNguoiTimNguonid = Convert.ToInt32(ddlNguoiTimNguon.DataKeys[e.RowIndex].Value);
        int intChẹck = objNguoiTimNguon.removeNguoiTimNguon(intNguoiTimNguonid);
        if (intChẹck > 0)
        {
            this.lblMess.Text = "Xóa thành công bản ghi";
            ddlNguoiTimNguon.EditIndex = -1;
            loadNguoiTimNguon();
        }
        else
        {
            this.lblMess.Text = "Lỗi trong quá trình xóa bản ghi!";            
        }
    }

#endregion
#region "Parametter variables"
    // Ham lay Bind du lieu
    public SqlConnection ConnectionView
    {
        get
        {
            object obj2 = this.ViewState["ConnectionView"];
            if (obj2 != null)
            {
                return (SqlConnection)obj2;
            }
            return null;
        }
        set
        {
            this.ViewState["ConnectionView"] = value;
        }
    }
    #endregion     
#region "Events handle"
    //Check quyen han su dung
    private void CheckUserModule(int UserID, int ModuleID)
    {
        //objUser.CheckUserModule(UserID, ModuleID, ref boolRead, ref boolWrite
        //    , ref boolUpdate, ref boolDelete);
        //if (!boolRead)
        //{
        //    this.btnInsert.Visible = false;
        //    this.ddlNguoiTimNguon.Visible = false;
        //}
        //if (!boolWrite)
        //{
        //    this.btnInsert.Visible = false;
        //}
        //if (!boolUpdate)
        //{
        //    this.ddlNguoiTimNguon.Columns[3].Visible = false;
        //    this.ddlNguoiTimNguon.Columns[5].Visible = false;
        //    this.btnRemove.Visible = false;
        //}
        //if (!boolDelete)
        //{
        //    this.ddlNguoiTimNguon.Columns[4].Visible = false;
        //    this.ddlNguoiTimNguon.Visible = false;
        //    this.ddlNguoiTimNguon.Visible = true;
        //}
        //else
        //{
        //    this.ddlNguoiTimNguon.Visible = true;
        //}
    }
    private void loadDataAccess()
    {
        SqlConnection sqlConnec = ConnectData.getConnection();
        objNguoiTimNguon = new DANguoiTimNguon(sqlConnec);
        objNguoidung = new DANguoidung(sqlConnec);
    }
    //Main load
    protected void Page_Load(object sender, EventArgs e)
    {
            loadDataAccess();
            if (!Page.IsPostBack)
            {
                loadNguoiTimNguon();
            }
    }
 
    //Su kien bin from NguoiTimNguon
    protected void ddlNguoiTimNguon_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.DataItem != null)
            {
                e.Row.Attributes["onmouseover"] = "javascript:setMouseOverColor(this);";
                e.Row.Attributes["onmouseout"] = "javascript:setMouseOutColor(this);";
                
                // Modify
                //ImageButton lbtDeleteTemp = ((ImageButton)e.Row.FindControl("lbtDelete"));
                Button btnDeleteTemp = ((Button)e.Row.FindControl("btnDelete"));
                if (btnDeleteTemp != null)
                {
                    string strDelete = "Bạn chắc chắn muốn xóa OK , Bạn hủy lệnh CANCEL ";
                    btnDeleteTemp.Attributes.Add("Onclick", "javascript:if(confirm('" + strDelete + "')) {return true} else {return false};");
                }               
            }
        }

    }

    //Su kien xoa NguoiTimNguon
    protected void ddlNguoiTimNguon_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        this.lblMess.Text = "";
        DeleteNguoiTimNguon(sender, e);
    }
    
    protected void ddlNguoiTimNguon_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.ddlNguoiTimNguon.EditIndex = -1;
        this.ddlNguoiTimNguon.PageIndex = e.NewPageIndex;
        this.loadNguoiTimNguon();
    }
#endregion

}
